#!/bin/bash

######EDIT THIS TO REQUIRED PATH #########
GSPASSdirPath="/root/Desktop"

echo 'Generating environment for GSPass project in '$GSPASSdirPath

mkdir -m 777 $GSPASSdirPath/GSPass
mkdir -m 777 $GSPASSdirPath/GSPass/workspace
mkdir -m 777 $GSPASSdirPath/GSPass/logs
mkdir -m 777 $GSPASSdirPath/GSPass/logs/satlogs
cd $GSPASSdirPath/GSPass/logs
echo '' > ClientCommunicationException.log
echo '' > GSPASS.log
echo '' > SatelliteStubLog.log
echo '' > ServerCommunicationException.log

cd ..

svn checkout https://gspass.googlecode.com/svn/sources $GSPASSdirPath/GSPass/sources/
svn checkout https://gspass.googlecode.com/svn/Infrastructure $GSPASSdirPath/GSPass/Infrastructure/

sedpath=${GSPASSdirPath//[\/]/\\/}

echo ''

echo 'Replacing paths for runproto app'
cd $GSPASSdirPath/GSPass/Infrastructure/ProtobufClassCreator/
sed  -i 's/\/root\/Desktop/'$sedpath'/g' runproto.desktop
echo 'Done'
echo ''

echo 'Replacing paths for GSPass and SatelliteSTUB app'
cd $GSPASSdirPath/GSPass/sources/execFiles/
sed  -i 's/\/root\/Desktop/'$sedpath'/g' GSPass.desktop
sed  -i 's/\/root\/Desktop/'$sedpath'/g' SatelliteSTUB.desktop
echo 'Done'
echo ''

echo 'Replacing paths in CoreSettings.cpp'
cd $GSPASSdirPath/GSPass/sources/GSPass-Settings/CoreSettings
sed  -i 's/\/root\/Desktop/'$sedpath'/g' CoreSettings.cpp
echo 'Done'
echo ''

echo 'Replacing paths in core.ini'
cd $GSPASSdirPath/GSPass/sources/SettingsFiles
sed  -i 's/\/root\/Desktop/'$sedpath'/g' core.ini
echo 'Done'
echo ''

echo 'Generation of GSPass environment completed, follow this steps to successfully running the project:'
echo 'Use workspace directory '$GSPASSdirPath'/GSPass/workspace in eclipse'
echo 'Import all projects and build all'
echo 'double click on SatelliteSTUB and then GSPass in '$GSPASSdirPath'/GSPass/sources/execFiles/'
echo 'press any key for exit'
read finishscriptok
